package com.eigland.eigaland_lib.base

import android.os.Parcel
import android.os.Parcelable
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch

abstract class BaseVM: ViewModel(), LifecycleObserver,CoroutineScope by CoroutineScope(Dispatchers.Main + SupervisorJob())

{
     var progressLoadingStatus = MutableLiveData<Boolean>()

     /**
      * init data or something
      */
     abstract fun initData()

     /**
      * call this method when you're current page prepare finish (release resource or more..)
      *
      */
     abstract fun destroy()
     /**
      * if your application crashes suddenly,you can save some data or status here
      */
     abstract fun saveData()
     /**
      * The page is hide, will call this
      */
     abstract fun onResume()


     private fun launchOnUI(block: suspend CoroutineScope.() -> Unit) {

          viewModelScope.launch { block() }

     }
}